<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set('memory_limit', '100M');

require_once ('../../api/classes/gbif.checklist-2-1.php');
require_once ('../../api/classes/gbif.custom-eml.php');

$template = trim($_REQUEST['template']);
$template = ($template == '') ? '../../templates/Merged-Checklist/checklist-2.1.xlsx' : $template;
$folder = './files/';

$tplObj = new Checklist13($template);

$version = $tplObj->getVersion();

echo '<br> File Name : ' . $template;
echo '<br> File Version : ' . $version;

# Make metaxml
file_put_contents($folder . 'meta.xml', $tplObj->generateOccurrenceDataMeta() );

# Make EML
$eml = new CustomEml();
$sheet = $tplObj->getSheet(1);
$eml->createEmlFromWorksheet( $sheet );
$eml->generateXml(0);
$xml = $eml->getRawXml();
file_put_contents($folder . 'eml.xml', $xml );

# Make Checklist
var_dump( $tplObj->validateChecklistData() );
$tplObj->writeChecklistData($folder . "/checklist.csv");

$tplObj->zipArchive($folder . 'checklist.zip', $folder, array('eml.xml', 'meta.xml', 'checklist.csv'));

echo '<br>Zip File Path: <a href="' . $folder . 'checklist.zip' . '">checklist.zip</a>';
?>